<?php
declare(strict_types = 1);

namespace app\common\model\mysql;

use think\Model;

class SpecsValue extends Model
{
    protected $name = 'mall_specs_value';

    protected $pk = 'id';

    //状态
    const STATUS_NORMAL = 1;
    const STATUS_PEDDING = 0;
    const STATUS_DELETE = 99;

    static $statusArr = [
        self::STATUS_NORMAL => '正常',
        self::STATUS_PEDDING => '待审核',
        self::STATUS_DELETE => '删除',
    ];

    protected $autoWriteTimestamp = true;

    public function getNormalBySpecsId($id, $field="*")
    {
        $where = [
            "specs_id" => $id,
            'status' => self::STATUS_NORMAL,
        ];

        return $this->where($where)->field($field)->select();
    }

    public function findSpecsValueByname($name)
    {

        if (empty($name)) {
            return false;
        }

        $where = [
            'name' => $name,
        ];

        return $this->where($where)->find();
    }


    public function delSpecsValueById($id)
    {
        $specsValue = $this->find($id);
        if (!$specsValue) {
            return false;
        }

        return $specsValue->delete();
    }

}
